package clients

import (
	"io/ioutil"
	"k8s.io/klog/v2"
	"net/http"
)

// examples
func hello (w http.ResponseWriter, r *http.Request){
	if r.Method == "GET"{
		_, err := w.Write([]byte("Hi,I'm MapperSDK HttpServer"))
		if err != nil {
			w.WriteHeader(500)
			return
		}
	}else{
		dataByte,err := ioutil.ReadAll(r.Body)
		if err != nil {
			w.WriteHeader(500)
			return
		}
		dataString := string(dataByte)
		klog.V(1).Infof("The data received is %s",dataString)
		_, err = w.Write([]byte("Hi,I'm MapperSDK HttpServer"))
		if err != nil {
			w.WriteHeader(500)
			return
		}
	}
}

func sayBye(w http.ResponseWriter, r *http.Request) {
	_, err := w.Write([]byte("bye bye"))
	if err != nil {
		w.WriteHeader(500)
		return
	}
}


